using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AjGenesisStudio.Syntax;

namespace AjGenesisStudio.Documents
{
    public partial class TemplateDocument : Document
    {
        public TemplateDocument()
        {
            InitializeComponent();
            
            SetSyntax(SyntaxComposer.GetTemplateSyntax(string.Empty));
        }

        private Syntax.Syntax output_syntax;
        public Syntax.Syntax OutputSyntax
        {
            get { return output_syntax; }
            set {
                if (value != null)
                {
                    if (output_syntax == null || output_syntax.Path != value.Path)
                    {
                        SetSyntax(SyntaxComposer.GetTemplateSyntax(value.Path));
                        if (!string.IsNullOrEmpty(this.FilePath))
                        {
                            SyntaxHelper.SetSavedOuputSyntax(this.FilePath, value.Name);
                        }
                    }
                }
                output_syntax = value;
            }
        }

        private void TemplateDocument_Enter(object sender, EventArgs e)
        {
            //actualizar toolbar template
        }

        private void TemplateDocument_Load(object sender, EventArgs e)
        {
            RememberOutputSyn();
        }

        private void RememberOutputSyn()
        {
            if (!string.IsNullOrEmpty(this.FilePath))
            {
                string syn_name =
                    SyntaxHelper.GetSavedOuputSyntax(this.FilePath);

                if (syn_name != string.Empty)
                    this.OutputSyntax = SyntaxHelper.GetSyntaxFromName(syn_name);
            }
        }
    }
}